<!--
 * @author  dumeng
帮扶救助申请
-->
<template>
  <section class="apply-main">
    <el-collapse-transition>
      <section class="main-search merge">
        <span class="svg-container">
          <svg-icon icon-class="search" />
        </span>
        <el-input v-model.trim="listQuery.userName" placeholder="输入名称搜索" class="search-input" @keyup.enter.native="handleFilter" />
        <section class="search-btn">
          <el-button class="filter-item" type="primary" @click="handleFilter">搜索</el-button>
          <el-button type="primary" @click="handleReset">重置</el-button>
        </section>
      </section>
    </el-collapse-transition>

    <section class="main-buttons">
      <section class="main-buttons-title">
        <span>帮扶救助申请</span>
      </section>
      <section class="main-buttons-btns">
        <el-button style="margin-left: 10px;" @click="handleExport()">导出</el-button>
        <el-button style="margin-left: 10px;" @click="handleBack()">返回</el-button>
      </section>
    </section>

    <section class="classify-tab">
      <el-tabs v-model="active" @tab-click="handleTabClick">
        <el-tab-pane v-for="item in classifys" :key="item.dictValue" :label="item.dictName" :name="item.dictValue" />
      </el-tabs>
    </section>

    <section class="main-table">
      <v-table :list="list" tag="bfjzapply" :list-loading="listLoading" :filter-column="filtercolumn" :selection="false">
        <el-table-column label="操作" fixed="right" align="center" min-width="120" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button type="text" size="mini" @click="handleView(scope.row)">查看</el-button>
          </template>
        </el-table-column>
      </v-table>
      <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
    </section>

    <el-dialog v-el-drag-dialog title="查看" :visible.sync="visible" width="50%">
      <el-form label-position="left" size="mini">
        <el-row>
          <el-col :span="12">
            <el-form-item label="姓名：">
              <span>{{ view.userName || '' }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="证件号码：">
              <span>{{ view.idCard || '' }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="部门：">
              <span>{{ view.depName || '' }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="申请时间：">
              <span>{{ view.registTime || '' }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="申请描述：">
              <span>{{ view.note || '' }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="上传图片：">
              <div v-if="view.images && view.images.length > 0" class="image-items">
                <div v-for="(item, index) in view.images" :key="index" class="image-item">
                  <el-image :src="'/API-DOCUMENT/document/file/download?id=' + item.fileId">
                    <div slot="error" class="image-slot">
                      <i class="el-icon-picture-outline" />
                    </div>
                    <div slot="placeholder" class="image-slot">
                      <i class="el-icon-loading" />
                    </div>
                  </el-image>
                </div>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <section slot="footer" class="dialog-footer">
        <el-button type="primary" @click="visible = false">关 闭</el-button>
      </section>
    </el-dialog>
  </section>
</template>
<script>
import Pagination from '@/components/Pagination'
import VTable from '@/components/Table'
import { getDictByCode, queryPage, maskAPI, noMaskAPI } from './../api/apply'
import permission from '@/directive/permission/index.js'
import elDragDialog from '@/directive/el-drag-dialog'
import { exportSign } from '@/utils/fileImportOrExportSign'
import { exportCheck } from '@/utils/sensitiveInfoExportCheck'
import CryptoJS from '@/utils/aesJiaJM'
import { deepClone } from '@/utils/index'
export default {
  name: 'BfjzApply',
  components: { Pagination, VTable },
  directives: { permission, elDragDialog },
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 10,
        userName: ''
      },
      classifys: [],
      active: '',
      list: [],
      total: 0,
      listLoading: false,
      visible: false,
      view: {}
    }
  },
  created() {
    this.getClassify()
  },
  methods: {
    /**
     * 获取分类
     */
    getClassify() {
      return new Promise((resolve, reject) => {
        getDictByCode('BFJZSQ').then(res => {
          this.classifys = (res.data.data && res.data.data.length > 0) ? res.data.data[0].list : []
          this.active = this.classifys[0].dictValue
          this.getList()
        }).catch(error => {
          reject(error)
        })
      })
    },

    handleBack() {
      this.$router.back()
    },

    /**
     * 预览
     */
    handleView(row) {
      row = deepClone(row)
      if (row.idCard) {
        row.idCard = CryptoJS.$aesJieM(row.idCard)
      }
      this.view = Object.assign({}, row)

      this.view.images = JSON.parse(row.attachment)
      this.visible = true
    },

    handleExport() {
      const query = exportSign({
        type: 1,
        userName: this.listQuery.userName,
        typeType: this.active
      }).obj
      exportCheck('STAFF_SERVICE_HELPING', this.active, maskAPI, noMaskAPI, query, '报名信息.xls')
    },

    /**
     * 选项卡切换
     */
    handleTabClick(tab, event) {
      this.listQuery.page = 1
      this.getList()
    },

    filtercolumn(scope, item) {
      if (item === 'idCard' || item === 'phoneNum') {
        return CryptoJS.$aesJieM(scope.row[item])
      } else {
        return scope.row[item]
      }
    },

    handleReset() {
      this.listQuery.page = 1
      this.listQuery.userName = ''
      this.getList()
    },

    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },

    getList(obj) {
      this.listLoading = true
      var query = {
        type: 1,
        userName: this.listQuery.userName,
        page: obj ? obj.page : this.listQuery.page,
        pageSize: obj ? obj.limit : this.listQuery.limit,
        typeType: this.active
      }
      return new Promise((resolve, reject) => {
        queryPage(query).then(response => {
          this.list = response.data.data.rows
          this.total = response.data.data.total
          this.listLoading = false
        }).catch(error => {
          reject(error)
          this.listLoading = false
        })
      })
    }
  }
}
</script>
<style lang="scss">

.apply-main {
  padding: 10px;
  .main-search {
    background-color: #fff;
    padding: 0 10px;
    .svg-container {
      padding: 0 5px 0 10px;
      color: #bfced6;
      vertical-align: middle;
      display: inline-block;
    }
    .search-input {
      width: 60%;
      position: relative;
      &:after {
        content: '';
        position: absolute;
        left: -25px;
        right: 0;
        bottom: 8px;
        height: 1px;
        background: rgba(226, 227, 232, 1);
      }
      input {
        outline: none;
        background: transparent;
        border: none;
        outline: medium;
        padding: 0;
        &:focus {
          outline: none;
          background-color: transparent;
        }
      }
    }
    .search-btn {
      display: inline-block;
      float: right;
      .el-button.is-round {
        padding: 10px 30px;
        margin-right: 34px;
      }
      .search-more {
        font-size: 14px;
        font-weight: 500;
        @include font-color($mainColor);
        cursor: pointer;
        margin-left: 10px;
      }
    }

    &.merge {
      height: 50px;
      line-height: 50px;
    }

    &.separate {
      .search-inner {
        padding-top: 10px;
        .search-inner-item {
          .item-label {
            height: 30px;
            line-height: 30px;
            font-size: 14px;
            color: #a6a6a6;
            font-weight: 400;
          }
          .el-input {
            position: relative;
            &.el-date-editor input {
              padding-left: 30px;
            }
            .el-input__inner {
              border: none;
              padding: 0;
            }
            &:after {
              content: '';
              height: 1px;
              background-color: #e2e3e8;
              position: absolute;
              left: 0;
              right: 0;
              bottom: 0;
            }
          }
        }
      }
      .search-btn {
        text-align: center;
        display: block;
        float: none;
        height: 56px;
        line-height: 56px;
      }
    }
  }

  .classify-tab {
    width: 100%;
    margin: 10px 0;
    padding: 0 10px;
    background-color: #fff;
    display: flex;
    border-radius: 4px;
    .el-tabs__nav-wrap::after {
      display: none;
    }
    .el-tabs__header {
      margin: 0;
    }
  }

  .main-buttons {
    display: flex;
    line-height: 36px;
    margin-top: 10px;
    .main-buttons-title {
      flex: 1;
      height: 36px;
      line-height: 36px;
      font-size: 16px;
      font-weight: bold;
      color: rgba(51, 51, 51, 1);
    }
  }

  .image-items {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    .image-item {
      width: 100px;
      height: 100px;
      margin-right: 10px;
      margin-bottom: 10px;
      .el-image .image-slot {
        background-color: #f5f7fa;
      }
    }
  }
}
</style>
